package com.example.asus.myapplication;

import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;
import android.view.View;

import com.example.myprojectoffeixue.LoginActivity;
import com.example.myprojectoffeixue.MainActivity;
import com.example.myprojectoffeixue.R;
import com.example.myprojectoffeixue.ShanPingActivity;
import com.example.myprojectoffeixue.Switch;
import com.robotium.solo.Solo;

/**
 * Created by ASUS on 2016/9/26.
 */
public class LoginTest2 extends ActivityInstrumentationTestCase2 {
    public Solo solo;

    public LoginTest2() {
        super(LoginActivity.class);
    }
    @Override
    public void setUp() throws Exception {
        super.setUp();
        solo = new Solo(getInstrumentation(), getActivity());
    }

    public void testLogin6() throws Exception {
        Test();
    }

    public void Test() {
        solo.clearEditText(0);
        solo.clearEditText(1);
        solo.enterText(solo.getEditText(0), "15639767013");
        solo.enterText(solo.getEditText(1), "12345678");
        solo.clickOnText("登录");
        solo.sleep(5000);
        for(int i=0;i<1000;i++) {
            MainActivity ma1= (MainActivity) solo.getCurrentActivity();
            View V1=ma1.findViewById(R.id.cj_textview);
            MainActivity ma = (MainActivity) solo.getCurrentActivity();
            View V = ma.findViewById(R.id.shezhi_textview);
            MainActivity ma3 = (MainActivity) solo.getCurrentActivity();
            View V3 = ma.findViewById(R.id.sb_textview);
            int date= (int)(1+Math.random()*(10-1+1));
            if(date%3==0){
                solo.clickOnView(V1);
                solo.sleep(2000);
                boolean flag=solo.searchText("cj");
                assertEquals(true,flag);
                solo.clickOnText("cj");
                solo.sleep(2000);
                solo.clickOnText("cj2");
                solo.sleep(2000);
            }else if(date%3==1){
                solo.clickOnView(V);
                solo.sleep(2000);
                boolean flag2=solo.searchText("退出");
                assertEquals(true,flag2);
                solo.clickOnText("报警日志");
                solo.sleep(2000);
                solo.clickOnText("红外");
                solo.sleep(2000);
                solo.goBack();
                solo.clickOnText("门磁");
                solo.sleep(2000);
                solo.goBack();
                solo.clickOnText("报警日志");
                solo.sleep(2000);
                solo.clickOnText("权限设置");
                solo.sleep(1000);
                solo.clickOnText("授权一览");
                solo.sleep(1000);
                solo.clickOnText("共享");
                solo.sleep(2000);
                solo.clickOnText("接受");
                solo.sleep(2000);
                solo.goBack();
                solo.clickOnText("权限设置");
                solo.sleep(1000);
                solo.sleep(2000);
            }else if(date%3==2){
                solo.clickOnView(V3);
                solo.sleep(2000);
                boolean flag3=solo.searchText("开关");
                assertEquals(true,flag3);
                solo.clickOnText("开关");
                solo.sleep(2000);
                solo.clickOnImage(4);
                solo.sleep(5000);
                solo.clickOnImage(6);
                solo.sleep(5000);
                solo.clickOnImage(8);
                solo.sleep(5000);
                solo.clickLongInList(2);
                solo.sleep(2000);
                solo.clearEditText(0);
                solo.enterText(solo.getEditText(0), (i+1)+"");
                solo.clickOnText("确定");
                solo.sleep(1000);
                solo.assertCurrentActivity("错误了", "Switch", true);
                solo.goBack();
                //测试门锁
                solo.clickOnText("门锁");
                solo.sleep(2000);
                solo.clickOnImage(2);
                solo.sleep(7000);
                solo.clickLongInList(1);
                solo.sleep(2000);
                solo.clearEditText(0);
                solo.enterText(solo.getEditText(0), (i+1)+"");
                solo.clickOnText("确定");
                solo.sleep(2000);
                solo.goBack();

//测试取电开关
                solo.clickOnText("取电开关");
                solo.sleep(2000);
                solo.clickOnImage(2);
                solo.sleep(5000);
                solo.clickLongInList(1);
                solo.sleep(2000);
                solo.clickOnText("获取电量");
                solo.sleep(2000);
                solo.clickLongInList(1);
                solo.sleep(2000);
                solo.clickOnText("重命名");
                solo.sleep(2000);
                solo.clearEditText(0);
                solo.enterText(solo.getEditText(0), (i+1)+"");
                solo.clickOnText("确定");
                solo.sleep(2000);
                solo.goBack();
                //测试智能插座
                solo.clickOnText("智能插座");
                solo.sleep(2000);
                solo.clickOnImage(2);
                solo.sleep(3000);
                solo.clickLongInList(1);
                solo.sleep(2000);
                solo.clearEditText(0);
                solo.enterText(solo.getEditText(0), (i+1)+"");
                solo.clickOnText("确定");
                solo.sleep(2000);
                solo.goBack();
                //测试中央空调
                solo.clickOnText("中央空调");
                solo.clickOnImage(1);
                solo.sleep(2000);
                solo.clickOnImage(1);
                solo.sleep(2000);
                solo.clickOnImage(2);
                solo.sleep(2000);
                solo.clickOnImage(3);
                solo.sleep(2000);
                solo.clickOnImage(4);
                solo.sleep(2000);
                solo.clickOnImage(5);
                solo.sleep(2000);
                solo.clickOnImage(6);
                solo.sleep(2000);
                solo.clickOnImage(7);
                solo.sleep(2000);
                solo.waitForDialogToOpen();
                solo.clickOnText("确定");
                solo.sleep(2000);
                solo.goBack();
                solo.sleep(2000);

                solo.clickLongOnText("0");
                solo.sleep(2000);
                solo.clearEditText(0);
                solo.enterText(solo.getEditText(0), "0");
                solo.clickOnText("确定");
                solo.sleep(2000);
                solo.goBack();
            }

           /*测试开关

//测试退出
           /* solo.clickOnView(V1);
            solo.sleep(5000);
            solo.clickOnText("cj");
            solo.sleep(2000);
            solo.clickOnText("cj2");
            solo.sleep(2000);*/

         /*  solo.clickOnView(V);
           solo.sleep(2000);
           solo.clickOnText("报警日志");
           solo.sleep(2000);
           solo.clickOnText("红外");
           solo.sleep(2000);
           solo.goBack();
           solo.clickOnText("门磁");
           solo.sleep(2000);
           solo.goBack();
           solo.clickOnText("权限设置");
           solo.sleep(1000);
           solo.clickOnText("授权一览");
           solo.sleep(1000);
           solo.clickOnText("共享");
           solo.sleep(2000);
           solo.clickOnText("接受");
           solo.sleep(2000);
           solo.goBack();
           solo.sleep(2000);*/
          // solo.clickOnText("退出");
         //  solo.sleep(2000);
        }

   }

}
